package com.huadi.controller;

import com.huadi.domain.Teacher;
import com.huadi.service.TeacherService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;


@Controller
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService service;
    @RequestMapping("/addTeacher.do")
    public ModelAndView addTeacher(Teacher teacher){
        ModelAndView mv = new ModelAndView();
        String tips = "注册失败";
        int nums = service.addTeacher(teacher);
        if ( nums > 0){
            tips = "教师【"+teacher.getName()+"】注册成功";
        }

        mv.addObject("tips",tips);

        mv.setViewName("result");

        return mv;
    }


    @RequestMapping("/login")
    public ModelAndView login(Teacher teacher){
        ModelAndView mv = new ModelAndView();
        boolean flag= true;
        if (service.login(teacher.getTeacher_id(), teacher.getName())!=null)
            flag = true;
        if(flag){
            mv.setViewName("success");
        }
        else {
            mv.setViewName("result");
        }
        System.out.println("flag = " + flag);
        return mv;
    }



}
